package com.test.webdemo.dao;

import com.test.webdemo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class UserDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;
    public User getUserById(String id) {
        return jdbcTemplate.queryForObject("select * from user where id=?",new BeanPropertyRowMapper<>(User.class),id);
    }

    public void addUser(User user) {
        jdbcTemplate.update("insert into user(id, username, password, email, role, is_active, create_time, update_time) values(?, ?, ?, ?, ?, ?, ?, ?)",
                user.getId(), user.getUsername(), user.getPassword(), user.getEmail(), user.getRole(), user.getIsActive(), user.getCreateTime(), user.getUpdateTime());
    }
}
